<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@page import="com.cap.bts.framework.usermgnt.constant.EmployeeStatus"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>查找会员</title>
<%@include file="../include/include.jsp"%>
<link rel="stylesheet" type="text/css" href="${csspath }/public.css" />
<link rel="stylesheet" type="text/css" href="${csspath }/datepicker.css" />
<link rel="stylesheet" type="text/css" href="${csspath }/style_l.css" />
<script type="text/javascript" src="${jspath }/jquery/jquery-1.8.3.js"></script>
<script type="text/javascript" src="${layerPath}/layer.js"></script>
<script type="text/javascript" src="${layerPath}/extend/layer.ext.js"></script>
<script type="text/javascript" src="${jspath }/jquery.ui.min.js"></script>
<script type="text/javascript" src="${jspath }/ui.datepicker_zh-CN.js"></script>
<script type="text/javascript" src="${jspath }/jquery.blockUI.js"></script>
<script type="text/javascript" src="${jspath }/public.js"></script>
<script type="text/javascript" src="${jspath }/jquery.selectAll.js"></script>
<script type="text/javascript"
	src="${jspath}/jquery/jquery.ui.draggable.js"></script>
<script type="text/javascript" src="${jspath}/jquery/jquery.alerts.js"></script>
<script type="text/javascript" src="${jspath}/load_layer.js"></script>
<link rel="stylesheet" type="text/css"
	href="${csspath}/jquery.alerts.css" />

<link rel="stylesheet" type="text/css"
	href="${webcontext}/css/validationEngine.jquery.css" />
<script src="${jspath}/jquery/validate/jquery.validationEngine.js"
	type="text/javascript"></script>
<script src="${jspath}/jquery/validate/jquery.validationEngine-zh.js"
	type="text/javascript"></script>
<script type="text/javascript"
	src="${webcontext}/javascript/jquery/jquery.ui.draggable.js"></script>

<link rel="stylesheet" type="text/css"
	href="${bootstrapPath}/css/bootstrap.css" />
<script type="text/javascript" src="${bootstrapPath}/js/bootstrap.js"></script>
<style type="text/css">
.formError .formErrorContent {
	-moz-border-radius: 6px 6px 6px 6px;
	-moz-box-shadow: 0 0 6px #000000;
	background: none repeat scroll 0 0 #EE0101;
	border: 2px solid #DDDDDD;
	color: #FFFFFF;
	font-family: tahoma;
	font-size: 11px;
	padding: 4px 10px;
	width: 100px;
}


.curr-new{
background-color: #E7E2E2;font-weight:bold;border-bottom:2px solid #CCC;cursor: normal;
}
.new-member{display:inline;padding:7px 15px 1px 15px;cursor: pointer;}
.display-none{display:none;}
</style>

<script type="text/javascript">
	var myHeight = 0;
	
	function toggleNewBtn(){
		
		$("#newBtnBox").find("div").toggleClass("curr-new");
		
		$("#normalBox").toggleClass("display-none");
		$("#wechatBox").toggleClass("display-none");
		
	}
	$(function() {

		/* layer.alert("当前系统环境为测试环境，请勿进行真实业务操作！<br/>当前环境激活验证码和使用抵扣码均为 “111111”",{
			icon: 0,
			shade: 0.1,
			offset: ['180px', '400px']
		}); */

		//选中后该行高亮
		$('#dataTable tr').bind('click', function() {
			if (window.cur)
				window.cur.style.background = "";
			if (window.cur)
				window.cur.style.fontWeight = "normal";
			this.style.background = "#e8e8e8";
			this.style.fontWeight = "bold";
			window.cur = this;
			$(this).find("td input[type='radio']").attr("checked", true);
			$(this).find("td input[type='radio']").click();
		});

		// 设置鼠标点击行时选中改行第一列的单选按钮
// 		$("#dataTable tr").click(function() {
// 			$(this).find("td input[type='radio']").attr("checked", true);
// 			$(this).find("td input[type='radio']").click();
// 		});

		$("#toMemberPurchasePage")
				.click(
						function() {
							getCheckedLine("${webcontext}/crmdp/dealer/purchase/toMemberPurchase");
						});
		
		$("#toMarsMemberPurchasePage")
		.click(
				function() {
					if ($("#idHtxt").val() == "") {
						jAlert('请选择会员后再进行操作！', '提示');
						return;
					}
					
					var id=$("#idHtxt").val();
					var phone=$("#mobilePhoneHtxt").val();
					var name=$("#memberNameHtxt").val();
					var carplate=$("#carPlateHtxt").val();
					
					var  url = "${webcontext}/crmdp/dealer/purchase/toMemberPurchaseMars?customerId="+id+"&mobilePhone="+phone+"&customerName="+name+"&carPlate="+carplate;
					//iframe层
					layer.open({
					    type: 2,
					    title: 'Mars购买画面',
					    shadeClose: false,
					    closeBtn: false,
					    shade: 0.1, 
					    offset : ['10%' , '25%'],
					    area: ['700px', '500px'],
					    content: url,//iframe的url
					    end: function(){ 
					    	//关闭弹出层后回调方法
					    	window.location.href="${webcontext}/crmdp/dealer/member/redirectMaintainMemberPage";
					    }
					}); 
				}
		);

		$("#toCreateMemberPage")
				.click(
						function() {
							var  url = "${webcontext}/crmdp/dealer/member/toCreateMemberPage";
							layer.open({
								type :1,
									offset : ['10px' , '25%'],
								    area: ['600px', '450px'],
								    scrollbar: false,
								    title: '新建会员', 
								    content: 
								    	 "<div style='height:90%;margin-top:15px;'>" 
								    	+ "<div style='border-bottom:2px solid #CCC;' id='newBtnBox'>"
								    	+ "  <div class='curr-new new-member' onclick='toggleNewBtn()'>手工新建</div><div onclick='toggleNewBtn()' class='new-member'>从微信会员选择</div></div>"
								    	+'<div id="normalBox" style="width:100%;height:100%;"><iframe src="${webcontext}/crmdp/dealer/member/toCreateMemberPage" style="width:90%;height:100%;border:none;margin-left:50px;"></iframe></div>'
								    	+'<div id="wechatBox" style="width:100%;height:100%;" class="display-none"><iframe src="${webcontext}/crmdp/dealer/member/toSelectMemberFromWechatPage" style="width:100%;height:100%;border:none;"></iframe></div>'
							   			+ "</div>"
							          ,
								    end: function(){ 
								    	//关闭弹出层后回调方法
								    	window.location.href="${webcontext}/crmdp/dealer/member/redirectMaintainMemberPage";
								    }		
							});
						});
		$("#toPurchaseUserPage").click(function() {
			window.location.href = "${webcontext}/crmdp/dealer/member/toPurchaseUser";
			//loadLayer(this, "${webcontext}/crmdp/dealer/member/toPurchaseUser" , 800, 250, 100, 600);
		});

		$("#toUpdateMemberPage")
				.click(
						function() {
							var objMobilePhone = $('#dataTable input[name="mobilePhone1"]');
							var objMemberName = $('#dataTable input[name="memberName1"]');
							var objCarPlate = $('#dataTable input[name="carPlate1"]');
							var objId = $('#dataTable input[name="id1"]');

							var mobilePhone;
							var memberName;
							var carPlate;
							var id;
							var flag = false;

							if (objId.length <= 0) {
								jAlert('请选择会员后再进行操作！', '提示');
								return;
							}

							for ( var i = 0; i < objId.length; i++) {

								if (objId[i].checked) {
									mobilePhone = objMobilePhone[i].value;
									memberName = objMemberName[i].value;
									carPlate = objCarPlate[i].value;
									id = objId[i].value;
									flag = true;
									break;
								}
							}

							if (flag) {
								var  url = "${webcontext}/crmdp/dealer/purchase/toUpdateMemberPage?mobilePhone="
									+ mobilePhone
									+ "&memberName="
									+ encodeURI(encodeURI(memberName))
									+ "&carPlate="
									+ encodeURI(encodeURI(carPlate))
									+ "&id=" + id + "&redirected=" + true;
								//iframe层
								layer.open({
								    type: 2,
								    title: '修改会员',
								    shadeClose: false,
								    closeBtn: false,
								    shade: 0.1, 
								    offset : ['10%' , '25%'],
								    area: ['600px', '400px'],
								    content: url,//iframe的url
								    end: function(){ 
								    	//关闭弹出层后回调方法
								    	window.location.href="${webcontext}/crmdp/dealer/member/redirectMaintainMemberPage";
								    }
								}); 
							} else {
								jAlert('请选择会员后再进行操作！', '提示');
								return;
							}
						});

		$("#redemptionPackageBtn")
				.click(
						function() {
							if ($("#idHtxt").val() == "") {
								jAlert('请选择会员后再进行操作！', '提示');
								return;
							}
							$.ajax({
										type : 'POST',
										url : '${webcontext}/crmdp/dealer/redemption/checkActivePackageExsit',
										data : "id=" + $("#idHtxt").val()
												+ "&carPlate="
												+ $("#carPlateHtxt").val(),
										dataType : 'json',
										success : function(data) {
											if (data == true) {
												$("#search_form")
														.attr('action',
																'${webcontext}/crmdp/dealer/redemption/showMemberPackageList');
												$("#search_form").submit();
											} else {
												jAlert(
														'该会员不存在已激活的套餐，请购买激活后在进行操作!',
														'提示');
												return;
											}
										}
									});
						});
		
		$("#redemptionDetailBtn")
				.click(
						function() {
							if ($("#idHtxt").val() == "") {
								jAlert('请选择会员后再进行操作！', '提示');
								return;
							}
							$.ajax({
										type : 'POST',
										url : '${webcontext}/crmdp/dealer/redemption/checkPackageExsit',
										data : "id=" + $("#idHtxt").val()
												+ "&carPlate="
												+ $("#carPlateHtxt").val(),
										dataType : 'json',
										success : function(data) {
											if (data == true) {
												$("#search_form")
														.attr('action',
																'${webcontext}/crmdp/dealer/report/showMemberPackagesReport');
												$("#search_form").submit();
											} else {
												jAlert(
														'该会员没有购买套餐，请购买套餐后再进行操作!',
														'提示');
												return;
											}
										}
									});
						});

		$("#toActivateMemberPage")
				.click(
						function() {
							getCheckedLine("${webcontext}/crmdp/dealer/activation/toGetMemberActivationPage");
						});
		
		$("#toActivateMemberPageMars")
		.click(
				function() {
					if ($("#idHtxt").val() == "") {
						jAlert('请选择会员后再进行操作！', '提示');
						return;
					}
					var id=$("#idHtxt").val();
					var phone=$("#mobilePhoneHtxt").val();
					var name=$("#memberNameHtxt").val();
					var carplate=$("#carPlateHtxt").val();
					
					var  url = "${webcontext}/crmdp/dealer/activation/toMemberActivationMars?customerId="+id+"&mobilePhone="+phone+"&customerName="+name+"&carPlate="+carplate;
					//iframe层
					layer.open({
					    type: 2,
					    title: 'Mars激活画面',
					    shadeClose: false,
					    closeBtn: false,
					    shade: 0.1, 
					    offset : ['10%' , '25%'],
					    area: ['700px', '500px'],
					    content: url,//iframe的url
					    end: function(){ 
					    	//关闭弹出层后回调方法
					    	window.location.href="${webcontext}/crmdp/dealer/member/redirectMaintainMemberPage";
					    }
					}); 
				}
		);
		
		$("#redemptionCouponBtn")
		.click(
				function() {
					if ($("#idHtxt").val() == "") {
						jAlert('请选择会员后再进行操作！', '提示');
						return;
					}
					//iframe层
					layer.open({
					    type: 2,
					    title: '使用优惠券',
					    shadeClose: false,
					    closeBtn: false,
					    shade: 0.1, 
					    offset : ['10%' , '25%'],
					    area: ['500px', '450px'],
					    content: '${webcontext}/crmdp/dealer/coupon/toCouponRedemption?id='+$("#idHtxt").val()+'&carPlate='+encodeURI(encodeURI($("#carPlateHtxt").val()))+'&mobilePhone='+ $("#mobilePhoneHtxt").val()+'&memberName='+encodeURI(encodeURI($("#memberNameHtxt").val())) //iframe的url
					}); 
				}
				);

		if ('${dto.isSelected}' == "") {
			$("#data_tab tr").find("td input[type='radio']").first().attr(
					"checked", true);
			$("#data_tab tr").find("td input[type='radio']").first().click();
		} else {
			var objId = $('#dataTable input[name="id1"]');
			for ( var i = 0; i < objId.length; i++) {
				if (objId[i].id == '${dto.isSelected}') {
					$("#data_tab tr").find("td input[id='${dto.isSelected}']")
							.attr("checked", true);
					$("#data_tab tr").find("td input[id='${dto.isSelected}']")
							.click();
					break;
				}
				if (i == objId.length - 1) {
					$("#data_tab tr").find("td input[type='radio']").first()
							.attr("checked", true);
					$("#data_tab tr").find("td input[type='radio']").first()
							.click();
				}
			}
		}
	});

	function existPackageCountNum(id, phone, name, carplate) {
		rdoChange(id, phone, name, carplate)
		$("#search_form").attr('action',
				'${webcontext}/crmdp/dealer/redemption/showMemberPackageList');
		$("#search_form").submit();

		//window.location.href="${webcontext}/crmdp/dealer/redemption/showMemberPackageList?id="+id+"&carPlate="+encodeURI(encodeURI(carPlate));
	}
	
	function toTransactionHistory(id, phone, name, carplate) {
		rdoChange(id, phone, name, carplate);
		$("#search_form").attr('action',
				'${webcontext}/crmdp/dealer/report/toTransactionHistory');
		$("#search_form").submit();

	}

	function getCheckedLine(url) {

		var objMobilePhone = $('#dataTable input[name="mobilePhone1"]');
		var objMemberName = $('#dataTable input[name="memberName1"]');
		var objCarPlate = $('#dataTable input[name="carPlate1"]');
		var objId = $('#dataTable input[name="id1"]');

		var mobilePhone;
		var memberName;
		var carPlate;
		var id;
		var flag = false;

		if (objId.length <= 0) {
			jAlert('请选择会员后再进行操作！', '提示');
			return;
		}

		for ( var i = 0; i < objId.length; i++) {

			if (objId[i].checked) {
				mobilePhone = objMobilePhone[i].value;
				memberName = objMemberName[i].value;
				carPlate = objCarPlate[i].value;
				id = objId[i].value;
				flag = true;
				break;
			}
		}

		if (flag) {
			location.href = url + "?mobilePhone=" + mobilePhone
					+ "&memberName=" + encodeURI(encodeURI(memberName))
					+ "&carPlate=" + encodeURI(encodeURI(carPlate)) + "&id="
					+ id;
		} else {
			jAlert('请选择会员后再进行操作！', '提示');
			return;
		}
	}

	function search() {
		document.getElementById("search_form").submit();
	}

	function rdoChange(id, phone, name, carplate) {
		//查询该会员是否存在套餐
		$("#idHtxt").val(id);
		$("#mobilePhoneHtxt").val(phone);
		$("#memberNameHtxt").val(name);
		$("#carPlateHtxt").val(carplate);
	}
</script>
</head>
<body>
	<!-- content -->
	<div id="content" style="height: 600px;width: 1140px;">
		<!-- wrap -->
		<div id="wrap">
			<!-- search_div -->
			<form:form  class="form-horizontal" id="search_form"
				action="${webcontext}/crmdp/dealer/member/getMaintainMemberPage"
				method="post" modelAttribute="dto">
				<input type="hidden" id="idHtxt" name="id">
				<input type="hidden" id="mobilePhoneHtxt" name="mobilePhone">
				<input type="hidden" id="memberNameHtxt" name="memberName">
				<input type="hidden" id="carPlateHtxt" name="carPlate">
				<div class="">
					<div class="spliter h_10"></div>
						<div class="form-group">
							<label class="col-sm-3 control-label" for="mobilePhoneOrCarPlate"
								style="margin-left: 240px; width: 110px;margin-top: 0px;">手机/车牌：</label>
							<div class="col-sm-4" style="width: 240px;">
								<input name="mobilePhoneOrCarPlate" class="form-control input-sm" id="mobilePhoneOrCarPlate"
									type="text" style="width: 200px;"  value="${dto.mobilePhoneOrCarPlate}"/>
							</div>
							<button type="submit" class="btn btn-success btn-sm"><i class="glyphicon glyphicon-search" style="color:#FFFFFF"></i>&nbsp;查询</button>
							<button type="reset" class="btn btn-success btn-sm"><i class="glyphicon glyphicon-trash" style="color:#FFFFFF"></i>&nbsp;重置</button>
						</div>
					<%-- <form:input path="mobilePhoneOrCarPlate" cssClass="validate[length[0,11]] text string"/>&nbsp;&nbsp; --%>

					<div class="spliter h_10"></div>
				</div>
				<!-- /search_div -->

				<!-- page_div -->

				<!-- /page_div -->
				<!-- data_div -->
				<div id="dataTable" class="data_div">
					<div>
						<button type="button" class="btn btn-success btn-xs"
							id="toCreateMemberPage">
							<i class="glyphicon glyphicon-user" style="color: #FFFFFF"></i>新建会员
						</button>
						<button type="button" class="btn btn-success btn-xs"
							id="toUpdateMemberPage">
							<i class="glyphicon glyphicon-pencil" style="color: #FFFFFF"></i>修改会员
						</button>
						<button type="button" class="btn btn-success btn-xs"
							id="toMemberPurchasePage">
							<i class="glyphicon glyphicon-shopping-cart"
								style="color: #FFFFFF"></i>购买
						</button>
					<!-- 	<button type="button" class="btn btn-success btn-xs"
							id="toMarsMemberPurchasePage">
							<i class="glyphicon glyphicon-shopping-cart"
								style="color: #FFFFFF"></i>Mars购买
						</button> -->
						<button type="button" class="btn btn-success btn-xs"
							id="toActivateMemberPage">
							<i class="glyphicon glyphicon-check" style="color: #FFFFFF"></i>激活
						</button>
			<!-- 			<button type="button" class="btn btn-success btn-xs"
							id="toActivateMemberPageMars">
							<i class="glyphicon glyphicon-check" style="color: #FFFFFF"></i>Mars激活
						</button> -->
						<button type="button" class="btn btn-success btn-xs"
							id="redemptionPackageBtn">
							<i class="glyphicon glyphicon-credit-card" style="color: #FFFFFF"></i>使用
						</button>
						<button type="button" class="btn btn-success btn-xs"
							id="redemptionCouponBtn">
							<i class="glyphicon glyphicon-tags" style="color: #FFFFFF"></i>优惠券
						</button>
						<button type="button" class="btn btn-success btn-xs"
							id="redemptionDetailBtn" style="width: 100px;">
							<i class="glyphicon glyphicon-list-alt" style="color: #FFFFFF"></i>套餐使用明细
						</button>
					</div>
					<div class="spliter h_10"></div>
					<div style="width: 100%; height: auto; margin-top: 10px;">
						<table id="data_tab" class="table table-hover">
							<thead>
							<tr>
								<th width="10%" height="20" >选择</th>
								<th width="20%" height="20" >手机</th>
								<th width="20%" height="20" >姓名</th>
								<th width="15%" height="20" >车牌</th>
								<th width="15%" height="20" >创建日期</th>
								<th width="10%" height="20" >激活卡数量</th>
								<th width="10%" height="20" ></th>
							</tr>
							</thead>
							<tbody>
							<core:forEach items="${memberResultsDtoList}"
								var="memberResultsDto">
								<tr>
									<td class="text-left"><input type="radio" name="id1"
										id="radio${memberResultsDto.id}${memberResultsDto.carPlate}Rad"
										class="select_one" value="${memberResultsDto.id}"
										onClick="rdoChange('${memberResultsDto.id}','${memberResultsDto.mobilePhone}','${memberResultsDto.memberName}','${memberResultsDto.carPlate}')" /></td>
									<td class="text-left"><input type="hidden"
										name="mobilePhone1" value="${memberResultsDto.mobilePhone}">${memberResultsDto.mobilePhone}</td>
									<td class="text-left"><input type="hidden"
										name="memberName1" value="${memberResultsDto.memberName}">${memberResultsDto.memberName}</td>
									<td class="text-left"><input type="hidden" name="carPlate1"
										value="${memberResultsDto.carPlate}">${memberResultsDto.carPlate}</td>
									<td class="text-left">${memberResultsDto.memberCreateDate}</td>
									<core:if test="${memberResultsDto.existPackageCountNum != 0}">
										<td class="text-right"><a href="#"
											onclick="existPackageCountNum('${memberResultsDto.id}','${memberResultsDto.mobilePhone}','${memberResultsDto.memberName}','${memberResultsDto.carPlate}')">${memberResultsDto.existPackageCountNum}</a></td>
									</core:if>
									<core:if test="${memberResultsDto.existPackageCountNum == 0}">
										<td class="text-right">${memberResultsDto.existPackageCountNum}</td>
									</core:if>
									<td class="text-right"><a href="javascript:void(0)"
											onclick="toTransactionHistory('${memberResultsDto.id}','${memberResultsDto.mobilePhone}','${memberResultsDto.memberName}','${memberResultsDto.carPlate}')">交易历史</a></td>
								</tr>
							</core:forEach>
							</tbody>
						</table>
						<div class="page_div">
							<%@include file="../common/page.jsp"%>
						</div>
					</div>

				</div>
				<!-- /data_div -->
				<!-- page_div -->
				<!-- /page_div -->
			</form:form>
		</div>
		<!-- /wrap -->
	</div>
	<!-- /content -->

</body>

</html>